import { _decorator, Component, Node } from "cc";
import { eventDispatcher } from "../Constants";
import { EventType } from "../enums/EventType";
const { ccclass } = _decorator;

@ccclass("Menu")
export class Menu extends Component {

    public onLoad(): void {
        for (const child of this.node.children) {
            child.on(Node.EventType.TOUCH_END, this.handleCtr, this);
        }
    }

    public handleCtr(evt: TouchEvent): void {
        const target = evt.target as unknown as Node;
        const command = parseInt(target.name.split("_")[1]);
        eventDispatcher.emit(EventType.MENU_SELECT, command);
    }

}